package vno.sci.window
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	
	import org.aswing.AsWingManager;
	import org.aswing.AssetBackground;
	import org.aswing.BoxLayout;
	import org.aswing.EmptyLayout;
	import org.aswing.JButton;
	import org.aswing.JFrame;
	import org.aswing.JLabel;
	import org.aswing.JPanel;
	import org.aswing.JPopup;
	import org.aswing.JScrollPane;
	import org.aswing.JTextArea;
	import org.aswing.JWindow;
	import org.aswing.event.FrameEvent;
	import org.aswing.event.ResizedEvent;
	
	import vno.fux.res.pool.BitmapAttacher;
	import vno.sci.event.MonologEvent;
	import vno.sci.window.Monolog;
	import vno.sci.window.MonologModel;
	import vno.sci.window.MyButton;
	

	/**
	 * Monolog Controller.
	 * 
	 *  
	 * @author scinart
	 * 
	 */	
	public class MonologController extends EventDispatcher
	{	
		private var model:MonologModel;
		private var id:uint;
		public function MonologController(aModel:MonologModel, id:uint)
		{
			this.id = id;
			model = aModel;
		}
		public function get m():MonologModel
		{
			return model;
		}
		/**
		 * change Model content, hence update display.
		 * @param a
		 * 
		 * a can be associative array or an XML with the following properties.
		 * title
		 <p>text</p>
		 <p>htmlText</p>
		 <p>titleHeigh</p>
		 <p>buttonHeigh</p>
		 <p>windowWidth</p>
		 <p>windowHeight</p>
		 <p>textWidth</p>
		 <p>textHeight</p>
		 <p>x</p>
		 <p>y</p>
		 <p>visible</p>
		 */		
		public function changeModel(a:Object):void
		{
			model.changeData(a);
		}
		/**
		 * This one is private.
		 * Don't Use this. 
		 * @param event
		 * 
		 */		
		public function handle(event:Event):void
		{
			switch(event.type)
			{
				case MouseEvent.CLICK:
				{
					dispatchEvent(new MonologEvent(id, MonologEvent.CLICK));
				}
				default:
				{
					break;
				}
			}
		}
		/**
		 * This one is private.
		 * Don't call this method. 
		 * @param event
		 * 
		 */		
		public function handlePrev(event:MouseEvent):void
		{
			dispatchEvent(new MonologEvent(id,MonologEvent.PREVIOUS));
			event.stopImmediatePropagation();
		}
		/**
		 * This one is private.
		 * Don't call this method. 
		 * @param event
		 * 
		 */		
		public function handleNext(event:MouseEvent):void
		{
			dispatchEvent(new MonologEvent(id, MonologEvent.NEXT));
			event.stopImmediatePropagation();
		}
		public function handleSomeButton(event:MouseEvent):void
		{
			var ss:String = (event.target as JButton).getText();
			if(ss == "X")
			{
				dispatchEvent(new MonologEvent(id, MonologEvent.CLOSING));
				event.stopImmediatePropagation();
			}
		}
		
		public function debug_getNext():Object
		{
			var a:Object = {};
			a["title"] = model.windowWidthP;
			a["text"] = "model.windowWidthP" + model.windowWidthP;
			a["windowWidth"] = model.windowWidthP+10;
			a["windowHeight"] = model.windowHeightP+10;
			a["textWidth"] = a["windowWidth"];
			a["textHeight"] = (a["windowHeight"]-30)*4/5;
			a["x"] = 10;
			a["y"] = 10;
			return a;
		}	
	}
	

}